package nl.vu.few.ibivu.biomodels.shared;

import java.io.Serializable;

import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONValue;

import nl.vu.few.ibivu.biomodels.client.ui.cytoscapeweb.CytoscapeWebDataField;
import nl.vu.few.ibivu.biomodels.client.ui.cytoscapeweb.CytoscapeWebDataFieldType;

public class PetrifierDataField implements Serializable {
	private static final long serialVersionUID = -7993334921236556258L;
	String name;
	CytoscapeWebDataFieldType type;
	String defValue;
	
	private PetrifierDataField() {}

	public PetrifierDataField(String name, CytoscapeWebDataFieldType type, String jsonValue) {
		this();
		this.name = name;
		this.type = type;
		this.defValue = jsonValue;
	}
	
	public PetrifierDataField(String name, CytoscapeWebDataFieldType type) {
		this(name, type, null);
	}

	public PetrifierDataField(CytoscapeWebDataField field) {
		this(field.getName(), field.getType());
		JSONValue defValue = field.getDefValue();
		if (field.getDefValue() != null) {
			this.defValue = defValue.toString();
		}
	}

	public String getName() {
		return name;
	}

	public CytoscapeWebDataFieldType getType() {
		return type;
	}

	public String getDefValue() {
		return defValue;
	}

	public CytoscapeWebDataField cytoscapeWebDataField() {
		return CytoscapeWebDataField.create(name, type, (defValue == null) ? null : JSONParser.parseStrict(defValue));
	}
}
